package com.powernode.config;

import com.powernode.constant.Constants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 订单接收 消费者 配置类
 */
@Configuration
public class OrderRabbitConfig {

    // 定义队列
    @Bean
    public Queue orderQueue() {
        return new Queue(Constants.QUEUE_NAME_ORDER);
    }

    // 定义 路由模型交换机
    @Bean
    public DirectExchange orderDirectExchange() {
        return new DirectExchange(Constants.EXCHANGE_NAME_ORDER);
    }

    // 定义绑定
    @Bean
    public Binding bindingOrderQueuetoEx() {
        return BindingBuilder.bind(orderQueue()).to(orderDirectExchange()).with(Constants.ROUTING_KEY_ORDER);
    }
}
